Public Class HealthManager

    Public Const CountersCategoryName As String = "KanBan PGD Counters"

    Public Shared Function GetTotalOperationsCounter() As PerformanceCounter

        Dim name As String = "Total Operations Executed"
        If PerformanceCounterExists(name) Then
            Return GetCounter(name, ".")
        End If

        Return Nothing

    End Function

    Public Shared Function GetOperationsPerSecondCounter() As PerformanceCounter

        Dim name As String = "Operations per Second"
        If PerformanceCounterExists(name) Then
            Return GetCounter(name, ".")
        End If

        Return Nothing

    End Function

    Public Shared Function GetAverageTimePerOperationCounter() As PerformanceCounter

        Dim name As String = "Average Time per Operation"
        If PerformanceCounterExists(name) Then
            Return GetCounter(name, ".")
        End If

        Return Nothing

    End Function

    Public Shared Function GetAverageTimePerOperationBase() As PerformanceCounter

        Dim name As String = "Average Time per Operation Base"
        If PerformanceCounterExists(name) Then
            Return GetCounter(name, ".")
        End If

        Return Nothing

    End Function

    Private Shared Function PerformanceCounterExists(ByVal name As String) As Boolean
        If PerformanceCounterCategory.Exists(CountersCategoryName) Then
            Return PerformanceCounterCategory.CounterExists(name, CountersCategoryName)
        End If

        Return False

    End Function

    Private Shared Function GetCounter(ByVal name As String, ByVal machineName As String) As PerformanceCounter

        Dim counter As New PerformanceCounter()
        counter.CategoryName = CountersCategoryName
        counter.CounterName = name
        counter.MachineName = machineName
        counter.ReadOnly = False

        Return counter

    End Function


End Class
